<?php
class User_model extends Model {

	function __construct()
	{
		parent::Model();
	}

	function getMySQLPass($password) {
		
		return $this->db->select(sprintf("PASSWORD(%s) as password", $this->db->escape($password)))->get()->row()->password;
	}
    
	function getByLogin($username, $password) {
	
		$result = $this->db->where(sprintf("login_name = %s AND login_password = '%s'", $this->db->escape($username), $this->getMySQLPass($password)))->get('base_user');
		if ($result->num_rows() == 1) return $result->row(); else return NULL;
	}
	
	function getById($id) {
		
		return $this->db->get_where('base_user', array('id'=>$id))->row();
	}
	
	function updateActivity($id) {
		
		dump(local_date(now()));
		

		$this->db->where('id', $id);
		$this->db->update('base_user', array('last_activity' => now()));

	}
}
//--
//-- Table structure for table `base_user`
//--
//
//DROP TABLE IF EXISTS `base_user`;
//CREATE TABLE IF NOT EXISTS `base_user` (
//  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id',
//  `login_name` varchar(64) DEFAULT NULL COMMENT 'login name',
//  `login_password` varchar(41) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL COMMENT 'login password',
//  `real_name` varchar(64) DEFAULT NULL COMMENT 'real name',
//  `alias_name` varchar(64) DEFAULT NULL COMMENT 'alias name',
//  `email` varchar(256) DEFAULT NULL COMMENT 'email address',
//  `public_email` enum('yes','no','registered') CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT 'no' COMMENT 'public email',
//  `last_activity` timestamp NULL DEFAULT NULL COMMENT 'last activity',
//  `create_time` timestamp NULL DEFAULT NULL COMMENT 'create time',
//  `create_user` int(11) DEFAULT NULL COMMENT 'created by user',
//  PRIMARY KEY (`id`)
//) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
?>
